﻿/*
Copyright (c) 2011 Vratislav Cermak (vratacermak@gmail.com)
 
This file is part of TeachMe Project. See http://code.google.com/p/teach-me for more information.
 
TeachMe is an open source project. Using of TeachMe is free of charge.
It is distributed under GNU General Public License version 3 (GPLv3).
GPLv3 can be found at http://www.gnu.org/licenses/gpl.html.
 
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

using System;
using TeachMe.Application.Data;
using TeachMe.Application.Properties;

namespace TeachMe.Application
{
    public static class EnumCaptionResolver
    {
        public static string Translate(Priority priority)
        {
            priority.CheckValue<Priority>();

            switch (priority)
            {
                case Priority.VeryLow: 
                    return Resources.VeryLowPriority;
                case Priority.Low: 
                    return Resources.LowPriority;
                case Priority.Normal: 
                    return Resources.NormalPriority;
                case Priority.High: 
                    return Resources.HighPriority;
            }

            throw new ArgumentOutOfRangeException();
        }

        public static string Translate(Dictionary dictionary, EntryTextDirection direction)
        {
            string from = dictionary.Entries.From;
            string to = dictionary.Entries.To;
            Languages.Item languageFrom = Singleton<Languages>.Instance.GetByCode(from);
            Languages.Item languageTo = Singleton<Languages>.Instance.GetByCode(to);
            string translatedFrom = languageFrom != null ? languageFrom.Localized : from;
            string translatedTo = languageTo != null ? languageTo.Localized : to;

            switch (direction)
            {
                case EntryTextDirection.FromTo:
                    return String.Format(Resources.OneDirection, translatedFrom, translatedTo);
                case EntryTextDirection.ToFrom:
                    return String.Format(Resources.OneDirection, translatedTo, translatedFrom);
                case EntryTextDirection.Both:
                    return String.Format(Resources.BothDirections, translatedFrom, translatedTo);
            }

            throw new ArgumentOutOfRangeException();
        }

        public static string Translate(EntryTextDirection direction)
        {
            switch (direction)
            {
                case EntryTextDirection.FromTo:
                    return String.Format(Resources.OneDirection, Resources.FromColumn, Resources.ToColumn);
                case EntryTextDirection.ToFrom:
                    return String.Format(Resources.OneDirection, Resources.ToColumn, Resources.FromColumn);
                case EntryTextDirection.Both:
                    return String.Format(Resources.BothDirections, Resources.FromColumn, Resources.ToColumn);
            }

            throw new ArgumentOutOfRangeException();
        }
    }
}
